package net.sea.setup.ui.wizard.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JLabel;

import net.sea.commons.constants.AppConstants;
import net.sea.setup.config.custom.CustomConfig;
import net.sea.setup.config.custom.CustomConfigItem;
import net.sea.setup.ui.wizard.AbstractWizardPage;

/**
 * 选择应用服务器页面
 * 
 * @author 华成伍
 *
 */
@SuppressWarnings("serial")
public class ServerPage extends AbstractWizardPage {
	private JComboBox serveComboBox = new JComboBox();

	public ServerPage() {
		setBorder("\u5E94\u7528\u670D\u52A1\u5668");
		setLayout(null);

		JLabel tipLb1 = new JLabel(
				"\u5B89\u88C5\u5305\u5C06\u5E2E\u52A9\u60A8\u5B8C\u6210\u6613\u5F00\u5E73\u53F0\u5728\u5E94\u7528\u670D\u52A1\u5668\u4E0A\u7684\u90E8\u7F72\u5DE5\u4F5C\u3002");
		tipLb1.setBounds(70, 49, 339, 15);
		add(tipLb1);

		JLabel tipLb2 = new JLabel(
				"\u8BF7\u4ECE\u4EE5\u4E0B\u5217\u5217\u8868\u4E2D\u9009\u62E9\u5E94\u7528\u670D\u52A1\u5668\u3002");
		tipLb2.setBounds(70, 130, 339, 15);
		add(tipLb2);

		JLabel serverTipLb = new JLabel("\u5E94\u7528\u670D\u52A1\u5668\uFF1A");
		serverTipLb.setBounds(70, 236, 94, 15);
		add(serverTipLb);

		serveComboBox.setModel(new DefaultComboBoxModel(new String[] {
				"Tomcat"}));
		serveComboBox.setBounds(197, 233, 194, 21);
		serveComboBox.setEnabled(false);
		add(serveComboBox);
	}

	@Override
	public PageResult validateInput() {
		return new PageResult(true);
	}

	@SuppressWarnings("unchecked")
	@Override
	protected List<CustomConfig> createCustomConfig() {
		CustomConfig config = new CustomConfig();
		config.setType("应用服务器");
		CustomConfigItem item = new CustomConfigItem();
		item.setKey("选择的应用服务器");
		item.setValue((String) serveComboBox.getSelectedItem());
		config.addItem(item);
		
		List<CustomConfig> configs = new ArrayList<CustomConfig>();
		configs.add(config);
		
		// 保存配置系统到系统上下文
		Map<String, CustomConfig> customCfgMap = (Map<String, CustomConfig>) contextInst
				.getAttribute(AppConstants.CUSTOM_CONFIG_MAP_KEY);
		customCfgMap.put(this.getClass().getName(), config);
		return configs;
	}
}
